package com.sakura.test;

import com.sakura.bean.Red;
import com.sakura.config.MainConfigOfAutowired;
import com.sakura.dao.BookDao;
import com.sakura.service.BookService;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author Sakura
 * @Date 2023-02-24 14:19
 */
public class IOCTest_Autowired {

    @Test
    public void testAutowired(){
        AnnotationConfigApplicationContext configApplicationContext
                =new AnnotationConfigApplicationContext(MainConfigOfAutowired.class);

        BookService bookService = configApplicationContext.getBean(BookService.class);
        System.out.println("bookService = " + bookService);

        BookDao bookDao = (BookDao) configApplicationContext.getBean(BookDao.class);
        System.out.println("bookDao = " + bookDao);

        Red red = (Red) configApplicationContext.getBean("red");
        System.out.println("red = " + red);

        configApplicationContext.close();

    }
}
